package com.neusoft.elm.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.neusoft.elm.dao.BusinessDao;
import com.neusoft.elm.po.Business;
import com.neusoft.elm.util.DBUtil;

public class BusinessDaoImpl implements BusinessDao {
	
	Connection con =null;
	PreparedStatement pst = null;
	ResultSet rs = null;
	
	
	
	public List<Business> listBusiness(String businessName,String businessAddress){
		
		//String sql = "select * from business where 1=1";
		
		StringBuffer sql = new StringBuffer("select * from business where 1=1");
		if(businessName!=null&&!businessName.equals("")){
			sql.append("AND businessname like '%" + businessAddress + "%'");
		}
		if(businessName!=null&&!businessAddress.equals("")){
			sql.append("AND businessAddress like '%" + businessAddress + "%'");
		}
		List<Business> list = new ArrayList();
		
		//2.发送sql
	    try {
	    	con = DBUtil.getConnection();
			pst = con.prepareStatement(sql.toString());
			rs = pst.executeQuery();
			while(rs.next()){
				Business business = new Business();
				business.setBusinessAddress(rs.getString("businessAddress"));
				business.setBusinessExplain(rs.getString("businessExplain"));
				business.setBusinessId(rs.getInt("businessId"));
				business.setBusinessName(rs.getString("businessName"));
				business.setDeliveryPrice(rs.getDouble("deliveryPrice"));
				business.setPassword(rs.getString("password"));
				business.setStarPrice(rs.getDouble("starPrice"));
				list.add(business);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtil.closeAll(rs, pst, con);
		}
		
		
		return list;
	}

	

}
